$(function () {
    var $name = $("#name");
    var $phe = $("#name_error");
    var $psw = $("#password");
    var $pse = $("#psw_error");
    var $sub = $("#submit1");
    $sub[0].disabled = true;
    $name.focus(function () {
        $phe.html("请输入管理员账号！");
        $phe.css("color", "rgba(0,200,188,0.8)");
    });
    $name.blur(function () {
        var name = $name.val();
        if (name === '') {
            isError($phe, $sub, "请输入管理员账号在登录！");
            return;
        }
        $phe.html("检测中...").css("color", "rgba(0,200,188,0.8)");
        $.post("/admin/checkName.action",
            "name=" + name,
            function (data) {
                if (data === 0) {
                    isError($phe, $sub, "账号不存在，请确认后重试！");
                    return;
                }
                $phe.html("输入正确！");
                $sub[0].disabled = false;
            });
    });
    $psw.focus(function () {
        $pse.html("请输入密码！");
        $pse.css("color", "rgba(0,200,188,0.8)");
    });
    $psw.blur(function () {
        var psw = $psw.val();
        var reg = /[^0-9A-z_.]/;
        if (psw === '') {
            isError($pse, $sub, "请输入密码！");
            return;
        }
        if (reg.test(psw) === true) {
            isError($pse, $sub, "密码由大小写字母数字下划线点组成！");
            return;
        }
        $pse.html("输入正确！");
        $sub[0].disabled = false;
    });
    $("input").focus(function () {
        $("#error1").html("");
    })
});

function isError(ele1, ele2, str) {
    $(ele1).html(str);
    $(ele1).css("color", "rgba(255,0,0,0.8)");
    $(ele2).attr("disabled", true);
}

function checkForm() {
    var name = $("#name").val();
    var psw = $("#password").val();
    if (name === ''){
        $("#name_error").html("请输入账户名！").css("color", "rgba(255,0,0,0.8)");
        return false;
    }
    if (psw === ''){
        $("#psw_error").html("请输入密码！").css("color", "rgba(255,0,0,0.8)");
        return false;
    }
    return true;
}